package com.dylan.magic.common.util;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
 * @author : ankang
 * @date : 2019/8/17 16:32
 * @Description :
 */
public class MapBuilder<K, V> {

    private Map<K, V> map;

    public static <K, V> MapBuilder<K, V> create(Supplier<Map<K, V>> collectionFactory) {
        MapBuilder<K, V> mapBuilder = new MapBuilder<>();
        mapBuilder.map = collectionFactory.get();
        return mapBuilder;
    }
    public static <K, V> MapBuilder<K, V> create() {
        MapBuilder<K, V> mapBuilder = new MapBuilder<>();
        mapBuilder.map = new HashMap<>();
        return mapBuilder;
    }

    public MapBuilder<K, V> put(K key, V value) {
        map.put(key, value);
        return this;
    }

    public MapBuilder<K, V> putAll(Map<? extends K, ? extends V> m) {
        map.putAll(m);
        return this;
    }

    public MapBuilder<K, V> remove(K key) {
        map.remove(key);
        return this;
    }

    public Map<K, V> build() {
        return this.map;
    }
}
